<?php
//短信订阅程序
session_start();
include_once('./common.inc.php');
InitGP('action'); //初始化变量全局返回

if(empty($action)){
?>
<DIV style="WIDTH: 400px; VISIBILITY: inherit" id=sms-subscribe-dialog>
<DIV class=bd>
<DIV class="common-dialog sms-subscribe-dialog-c">
<DIV class=body>
<FORM id="sms-subscribe-form" method="post" action="mobile.php?action=check">
<H4>短信订阅每日团购信息</H4>
<P class=mobile><LABEL for=sms-subscribe-mobile>手机号</LABEL><INPUT id=sms-subscribe-mobile class=f-text maxLength=20 name=mobile><SPAN class=tip>请输入您的手机号</SPAN></P>
<P class=enter><LABEL for=sms-subscribe-captcha>验证码</LABEL><INPUT id=sms-subscribe-captcha class=f-text maxLength=20 name=code><SPAN class=tip>按下图字符填写，不区分大小写</SPAN></P>
<P class="captcha cf"><IMG id=sms-subscribe-captcha-img src="includes/code/securimage_show.php?sid=<?php echo md5(time()) ?>" width=100 height=50  style="padding-left: 5px; border: 0;cursor:hand" onclick='this.src=this.src+"&"+Math.random();' alt="点击刷新验证码"><SPAN id=sms-subscribe-captcha-change>看不清楚？点击验证码刷新</SPAN></P>
<P class=act><INPUT value=1 type=hidden name=cityid><INPUT  value=发送认证码 type=submit></P>
</FORM>
</DIV>
</DIV>
</DIV>
</DIV>
<?php
}elseif($action=="check"){
	InitGP(array("code","mobile"),"P",1); //初始化变量全局返回
	include(INC_PATH."/code/securimage.php");
	$img = new Securimage();
	$valid = $img->check($code);
	if($valid != true) {
  		showmsg("验证码错误","-1");
  		exit;
  	}
  	if (!GetNum($mobile) ||!is_mobile($mobile)) {
  		showmsg("手机号为空或格式错误!","-1");
  		exit;
  	}
	include_once(INC_PATH."/sendsms.class.php");
	$sms=new SendsmsClass();
	$checkcode=randomkeys(5,"ALL");
	set_cookie('checkcode',cookie_authcode($checkcode,'ENCODE'));//设置保存到cookie
	$msg="您好，短信订阅认证码：{$checkcode} 请出填写到认证表单提交订阅!";
	$msg=urlencode($msg);
	$info=$sms->send($mobile,$msg);

	if($info){
		//显示让输入认证码表单
	?>
<DIV style="WIDTH: 400px; VISIBILITY: inherit" id=sms-subscribe-dialog>
<DIV class=bd>
<DIV class="common-dialog sms-subscribe-dialog-c">
<DIV class=body>
<FORM id="sms-subscribe-form" method="post" action="mobile.php?action=add">
<H4>短信订阅每日团购信息</H4>
<P class=mobile><LABEL for=sms-subscribe-mobile>认证码</LABEL><INPUT id=sms-subscribe-mobile class=f-text maxLength=20 name=checkcode><SPAN class=tip>请输入您的手机号收到的认证码</SPAN></P>
<input type="hidden" name="mobile" value="<?php echo $mobile?>">
<P class=act><INPUT value=1 type=hidden name=cityid><INPUT value=订阅 type=submit></P>
</FORM>
</DIV>
</DIV>
</DIV>
</DIV>
	<?php	
	}else {
		showmsg("认证码发送失败","-1");
	}
}elseif($action=="add"){
	InitGP(array("checkcode","mobile"),"P",1); //初始化变量全局返回
	//接受认证码对比 提示成功或者失败
	$cookiecheckcode=get_cookie('checkcode');
	$cookiecheckcode=cookie_authcode($cookiecheckcode,'DECODE');
	if($checkcode==$cookiecheckcode){
	//添加记录
		include_once(INC_PATH."/mobile.class.php");
		$mob=new MobileClass();
		$info=$mob->add($mobile,$_USERS['uid'],$_cityid);
		if($info=="OK")
		showmsg("短信订阅成功!","mobile.php");
		else
		showmsg("短信订阅失败!","mobile.php");
	}else{
		showmsg("认证码不正确!","mobile.php");
	}	
}
?>

<style>
#sms-subscribe-dialog .bd {
	padding: 1px;
	background: #fff;
}
#sms-subscribe-dialog .body {
	padding: 0px 50px 0px;
}
#sms-subscribe-dialog h4 {
	margin: 10px 0;
}
#sms-subscribe-dialog p {
	clear: both;
	zoom: 1;
}
#sms-subscribe-dialog label {
	float: left;
	width: 60px;
	padding-top: 1px;
	*padding-top: 2px;
}
#sms-subscribe-dialog .f-text {
	float: left;
	width: 160px;
}
#sms-subscribe-dialog .tip {
	clear: both;
	float: left;
	width: 200px;
	padding-left: 60px;
	*padding-top: 2px;
	font-size: 12px;
	color: #999;
}
#sms-subscribe-dialog .commit {
	display: block;
	width: 92px;
	height: 24px;
	background: url(i/button-sms-commit.gif) no-repeat 0 0;
	border: 1px solid #fff;
	border-width: 0;
	text-indent: -999em;
	cursor: pointer;
}
#sms-subscribe-dialog .confirm {
	width: 65px;
	background-position: 0 -100px;
}
#sms-subscribe-dialog .mobile {
	padding-top: 10px;
}
#sms-subscribe-dialog .enter {
	padding-top: 10px;
}
#sms-subscribe-dialog .captcha {
	padding: 5px 0 0 60px;
}
#sms-subscribe-dialog .captcha img {
	float: left;
}
#sms-subscribe-dialog .captcha span {
	float: left;
	width: 100px;
	margin: 20px 0 0 5px;
	font-size: 12px;
	text-decoration: underline;
	color: #399;
	cursor: pointer;
}
#sms-subscribe-dialog .noti {
	padding: 5px 0 10px;
}
#sms-subscribe-dialog .noti strong {
	color: #c33;
}
#sms-subscribe-dialog .succ {
	margin: 30px 0 10px 20px;
	padding-left: 73px;
	padding-top: 5px;
	min-height: 51px;
	_height: 51px;
	background: url(i/bg-sys-icon-succ.gif) no-repeat 0 0;
	zoom: 1;
}
#sms-subscribe-dialog .title {
	font-size: 16px;
	font-family: '黑体',arial,sans-serif;
}
#sms-subscribe-dialog .notice {
	font-size: 12px;
	color: #999;
}
#sms-subscribe-dialog .act {
	margin-top: 15px;
	padding-left: 60px;
}
</style>
